<?php

/**
 * XHTML_Bdo, xhtml_lib
 * 
 * This file contains the source code for the XHTML_Bdo class.
 * @author Fernando Jimenez Mocobono <fjmcool@gmail.com>
 * @version 0.1
 * @package xhtml_lib
 */

include_once "XHTML_Common_Element.php";
include_once "XHTML__Special_Pre.php";
include_once "XHTML_Inline.php";


/**
 * The XHTML_Bdo class is a handler for the bdo xhtml-strict tag as a part
 * of a xhtml-strict php-handler implementation.
 */
class XHTML_Bdo extends XHTML_Common_Element implements XHTML__Special_Pre {
    
    // inner elements
    
    /**
     * XHTML_Inline elements the bdo element has in its content.
     *
     * @var array
     */
    protected $elements;


    // Methods
    
    /**
     * Constructs a XHTML_Bdo object with its required dir attribute.
     */
    function __construct($dir)
    {
        $this->dir = $dir;
        settype($this->elements, "array");
    }
    
    /**
     * Sets the XHTML_Inline elements array.
     *
     * @param array
     */
    function setElements($elements) {
        $this->elements = $elements;
    }
    
    /**
     * Gets the XHTML_Inline elements array.
     *
     * @return array
     */
    function getElements()
    {
        return $this->elements;
    }
    
    /**
     * Adds a XHTML_Inline element to the inner array of this object.
     * 
     * @param XHTML_Inline
     */
    function addElement(XHTML_Inline $element)
    {
        array_push($this->elements, $element);
    }
    
    /**
     * Removes a XHTML_Inline element from the inner array of this object.
     * 
     * @param XHTML_Inline
     */
    function removeElement(XHTML_Inline $element)
    {
        if (($res = array_search($element, $this->elements)) !== false) {
            unset($this->element[$res]);
        }
        }

        // Overriding the toString method for a proper implementation.
        
    /**
    * Returns the string representation for echoing the class atributes.
    *
    * @return string
    */
    function toString()
    {
        $auxString = "<bdo".parent::toString();

        $auxString = $auxString.">\n";

        /*
        * Additions of the inner elements of the bdo element to the return
        * string.
        */
        if (count($this->elements) > 0) {
            foreach ($this->elements as $element) {
                $auxString = $auxString.$element->toString();
            }
            }
            
            $auxString = $auxString."</bdo>\n";

            return $auxString;
            }
            
            }

            ?>